<div [@routerTransition]>
    <div class="m-subheader">
        <div class="d-flex align-items-center">
            <div class="mr-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    型号与批次管理
                </h3>
                <span class="m-section__sub">
                    型号与批次对应关系管理
                </span>
            </div>
        </div>
    </div>
    <div class="m-content">
        <div class="row">
            <div class="col-lg-5">
                <div class="m-portlet m-portlet--mobile">
                    <div class="m-portlet__head">
                        <div class="m-portlet__head-caption">
                            <div class="m-portlet__head-title">
                                <h3 class="m-portlet__head-text">
                                    型号列表
                                </h3>
                            </div>
                        </div>
                        <div class="m-portlet__head-tools">
                            <button (click)="createOrEditModelModal.show()" class="btn btn-primary">
                                <i class="fa fa-plus"></i> 添加型号
                            </button>
                        </div>
                    </div>
                    <div class="m-portlet__body">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form m-form--label-align-right">
                                <div class="row align-items-center m--margin-bottom-10">
                                    <div class="col-xl-12">
                                        <div class="form-group m-form__group align-items-center">
                                            <div class="input-group">
                                                <input
                                                    [(ngModel)]="filterText"
                                                    name="filterText"
                                                    autoFocus
                                                    class="form-control m-input"
                                                    [placeholder]="l('SearchWithThreeDot')"
                                                    type="text"
                                                />
                                                <span class="input-group-btn">
                                                    <button (click)="getModels()" class="btn btn-primary" type="submit">
                                                        <i class="flaticon-search-1"></i>
                                                    </button>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>

                        <div class="row align-items-center">
                            <div
                                class="model-datable primeng-datatable-container"
                                [busyIf]="primengTableHelper.isLoading"
                            >
                                <p-table
                                    #dataTable
                                    (onLazyLoad)="getModels($event)"
                                    [value]="primengTableHelper.records"
                                    rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
                                    [paginator]="false"
                                    [lazy]="true"
                                    scrollable="true"
                                    ScrollWidth="100%"
                                    resizableColumns="primengTableHelper.resizableColumns"
                                    selectionMode="single"
                                    (onRowSelect)="selectModel($event)"
                                    [(selection)]="selectedModel"
                                >
                                    <ng-template pTemplate="header">
                                        <tr>
                                            <th style="width: 100px">{{ l("Actions") }}</th>
                                            <th width="80">
                                                型号
                                            </th>
                                            <th width="100">
                                                名称
                                            </th>
                                            <th width="150">
                                                描述
                                            </th>
                                        </tr>
                                    </ng-template>
                                    <ng-template pTemplate="body" let-record="$implicit">
                                        <tr [pSelectableRow]="record">
                                            <td style="width: 100px">
                                                <div class="btn-group dropdown" dropdown container="body">
                                                    <button
                                                        dropdownToggle
                                                        class="dropdown-toggle btn btn-sm btn-primary"
                                                    >
                                                        <i class="fa fa-cog"></i>
                                                        <span class="caret"></span>
                                                        {{ l("Actions") }}
                                                    </button>
                                                    <ul class="dropdown-menu" *dropdownMenu>
                                                        <li>
                                                            <a
                                                                href="javascript:;"
                                                                *ngIf="
                                                                    permission.isGranted(
                                                                        'Pages.Administration.Users.Edit'
                                                                    )
                                                                "
                                                                (click)="createOrEditModelModal.show(record.id)"
                                                                >{{ l("Edit") }}</a
                                                            >
                                                        </li>
                                                        <li>
                                                            <a href="javascript:;" (click)="deleteModel(record)">{{
                                                                l("Delete")
                                                            }}</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </td>
                                            <td width="80">
                                                {{ record.code }}
                                            </td>
                                            <td width="100">
                                                {{ record.name }}
                                            </td>
                                            <td width="150">
                                                {{ record.description }}
                                            </td>
                                        </tr>
                                    </ng-template>
                                </p-table>
                                <div class="primeng-paging-container">
                                    <p-paginator
                                        rows="{{ primengTableHelper.defaultRecordsCountPerPage }}"
                                        #paginator
                                        (onPageChange)="getModels($event)"
                                        [totalRecords]="primengTableHelper.totalRecordsCount"
                                        [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage"
                                    >
                                    </p-paginator>
                                    <span class="total-records-count">
                                        共计：{{ primengTableHelper.totalRecordsCount }}
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-7">
                <div class="m-portlet m-portlet--mobile">
                    <div class="m-portlet__head">
                        <div class="m-portlet__head-caption">
                            <div class="m-portlet__head-title">
                                <h3 class="m-portlet__head-text">
                                    发次列表 <span *ngIf="selectedModel.id">: </span>{{ selectedModel.code }}
                                </h3>
                            </div>
                        </div>
                        <div class="m-portlet__head-tools">
                            <button (click)="createOrEditFaciModal.show(selectedModel.id)" class="btn btn-primary">
                                <i class="fa fa-plus"></i> 添加发次
                            </button>
                        </div>
                    </div>
                    <div class="m-portlet__body">
                        <div class="row align-items-center">
                            <div class="primeng-datatable-container">
                                <p-table
                                    [value]="batchs"
                                    rows="20"
                                    emptyMessage="该型号还没有批次"
                                    scrollable="true"
                                    ScrollWidth="100%"
                                >
                                    <p-footer>
                                        <div class="text-left">共计: {{ batchs.length }}</div>
                                    </p-footer>

                                    <ng-template pTemplate="header">
                                        <tr>
                                            <th style="width: 100px">{{ l("Actions") }}</th>
                                            <th width="130">
                                                型号
                                            </th>
                                            <th width="130">
                                                名称
                                            </th>
                                            <th width="130">
                                                描述
                                            </th>
                                            <th width="150">
                                                计划交付日期
                                            </th>
                                        </tr>
                                    </ng-template>
                                    <ng-template pTemplate="body" let-record="$implicit">
                                        <tr>
                                            <td style="width: 100px">
                                                <div class="btn-group dropdown" dropdown container="body">
                                                    <button
                                                        dropdownToggle
                                                        class="dropdown-toggle btn btn-sm btn-primary"
                                                    >
                                                        <i class="fa fa-cog"></i>
                                                        <span class="caret"></span>
                                                        {{ l("Actions") }}
                                                    </button>
                                                    <ul class="dropdown-menu" *dropdownMenu>
                                                        <li>
                                                            <a
                                                                href="javascript:;"
                                                                *ngIf="
                                                                    permission.isGranted(
                                                                        'Pages.Administration.Users.Edit'
                                                                    )
                                                                "
                                                                (click)="
                                                                    createOrEditFaciModal.show(
                                                                        selectedModel.id,
                                                                        record.id
                                                                    )
                                                                "
                                                                >{{ l("Edit") }}</a
                                                            >
                                                        </li>
                                                        <li>
                                                            <a href="javascript:;" (click)="deleteBacth(record)">{{
                                                                l("Delete")
                                                            }}</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </td>
                                            <td width="130">
                                                {{ record.code }}
                                            </td>
                                            <td width="130">
                                                {{ record.name }}
                                            </td>
                                            <td width="130">
                                                {{ record.description }}
                                            </td>
                                            <td width="150">
                                                {{ record.plannedFinishDate | momentFormat: "YYYY-MM-DD" }}
                                            </td>
                                        </tr>
                                    </ng-template>
                                </p-table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <createOrEditModelModal #createOrEditModelModal (modalSave)="getModels()"></createOrEditModelModal>
    <createOrEditLaunchModal #createOrEditFaciModal (modalSave)="getBacths()"></createOrEditLaunchModal>
</div>
